/** Copyright Notice:

    Copyright (C) 2011 Ivo Wingelaar

    This software is provided 'as-is', without any express or implied
    warranty.  In no event will the authors be held liable for any damages
    arising from the use of this software.

    Permission is granted to anyone to use this software for any purpose,
    including commercial applications, and to alter it and redistribute it
    freely, subject to the following restrictions:

    1.  The origin of this software must not be misrepresented; you must not
        claim that you wrote the original software. If you use this software
        in a product, an acknowledgment in the product documentation would be
        appreciated but is not required.
    2.  Altered source versions must be plainly marked as such, and must not be
        misrepresented as being the original software.
    3.  This notice may not be removed or altered from any source distribution.

    Please note that the Myth Library is based in part on the work of Nikolaus
    Gebhardt (Irrlicht Engine) and I give full credits to him, and the people who
    helped him for making available an excellent piece of code.

**/

//
// MythCrypto.cpp 010: implementation of 'Myth Crypto'
//

#include "MythCrypto.hpp"
#include "MythCrypto_HashFunctionStub_C.hpp"
#include "MythCrypto_HashFunctionMD5_C.hpp"
#include "MythCrypto_HashFunctionRIPEMD_C.hpp"
#include "MythCrypto_HashFunctionSHA_C.hpp"
#include "MythCrypto_StreamCipherArcFour_C.hpp"
#include "MythCrypto_InputEncrypted_C.hpp"
#include "MythCrypto_OutputEncrypted_C.hpp"

namespace Myth
{
namespace Crypto
{

/** function             **/
/** create_hash_function **/
//! Creates a hashfunction.
/// \return HashFunction*
///         A pointer to the newly created hashfunction-object.
/// \param   E_HASH_FUNCTION function
///         The type of function you want to have.
_MYTH_CRYPTO_API_ HashFunction* _MYTH_CALL_CONV_ create_hash_function( E_HASH_FUNCTION function)
{
    switch(function)
    {
    case EHF_RIPEMD128:
        return new HashFunctionRIPEMD128_C();
    case EHF_RIPEMD160:
        return new HashFunctionRIPEMD160_C();
    case EHF_RIPEMD256:
        return new HashFunctionRIPEMD256_C();
    case EHF_RIPEMD320:
        return new HashFunctionRIPEMD320_C();
    case EHF_MD5:
        return new HashFunctionMD5_C();
    case EHF_SHA1:
        return new HashFunctionSHA1_C();
    case EHF_SHA256:
        return new HashFunctionSHA256_C();
    case EHF_SHA224:
        return new HashFunctionSHA224_C();
    case EHF_SHA512:
        return new HashFunctionSHA512_C();
    case EHF_SHA384:
        return new HashFunctionSHA384_C();
    default:
        return 0;
    }
}

/** function             **/
/** create_stream_cipher **/
//! Creates a streamcipher.
/// \return StreamCipher*
///         A pointer to the newly created streamcipher-object.
/// \param   E_STREAM_CIPHER cipher
///         The type of cipher you want to have.
/// \param   uint8_t *key
///         A pointer to a block of data you want to use as a key.
/// \param   uint32_t key_size
///         The length of the key.
_MYTH_CRYPTO_API_ StreamCipher* _MYTH_CALL_CONV_ create_stream_cipher( E_STREAM_CIPHER cipher,  uint8_t *key,  uint32_t key_size)
{
    switch(cipher)
    {
    case ESC_ARCFOUR:
        return new StreamCipherArcFour_C(key, key_size);

    default:
        return 0;
    }
}

} // namespace Crypto
} // namespace Myth
